package org.afun.oldhand.order.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.afun.oldhand.R;
import org.afun.oldhand.order.javaBean.ItemBean;

import java.util.List;

public class OrderItemAdapter extends RecyclerView.Adapter<OrderItemAdapter.OrderViewHolder> {
    private List<ItemBean> data;
    private Context context;
    private OnOrderRecyclerItemClickListener onOrderRecyclerItemClickListener;

    public OrderItemAdapter(List<ItemBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @NonNull
    @Override
    public OrderItemAdapter.OrderViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
//        View view = View.inflate(context, R.layout.order_listitem, null);
        View view= LayoutInflater.from(context).inflate(R.layout.order_listitem,parent,false);
        return new OrderViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull OrderItemAdapter.OrderViewHolder holder, int position) {
        //        viewHolder.coachImage.setImageDrawable();
        holder.coachName.setText(data.get(position).getCoachName());
        holder.date.setText(data.get(position).getDate());
        holder.status.setText(data.get(position).getStatus());
        holder.spendTime.setText(data.get(position).getSpendTime());
        holder.spendFee.setText(data.get(position).getSpendFee());
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    public class OrderViewHolder extends RecyclerView.ViewHolder {
        ImageView coachImage;
        TextView coachName;
        TextView date;
        TextView status;
        TextView spendTime;
        TextView spendFee;

        public OrderViewHolder(@NonNull View itemView) {
            super(itemView);
            coachImage = itemView.findViewById(R.id.coachImage);
            coachName = itemView.findViewById(R.id.coachName);
            date = itemView.findViewById(R.id.date);
            status = itemView.findViewById(R.id.status);
            spendTime = itemView.findViewById(R.id.spendTime);
            spendFee = itemView.findViewById(R.id.spendFee);

            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(onOrderRecyclerItemClickListener!=null){
                        onOrderRecyclerItemClickListener.onItemRecyclerItemClick(getAdapterPosition());
                    }
                }
            });

        }
    }

    public void setOrderItemClickListener(OnOrderRecyclerItemClickListener listener){
        onOrderRecyclerItemClickListener=listener;
    }

    public interface OnOrderRecyclerItemClickListener{
        void onItemRecyclerItemClick(int position);
    }
}
